﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using jqGrid.Models.NorthWind;

namespace jqGrid.Repositories.NorthWind
{
    public class OrdersRepository : IOrdersRepository
    {
        #region Fields
        NorthWindDataContext _dataContext = new NorthWindDataContext();
        #endregion

        #region IOrdersRepository Members
        public int GetOrdersCount()
        {
            return _dataContext.Orders.Count();
        }

        public IQueryable<Order> GetOrders(string sortExpression, string sortDirection, int pageIndex, int pageSize)
        {
            return _dataContext.Orders.OrderBy(sortExpression + " " + sortDirection).Skip(pageIndex * pageSize).Take(pageSize);
        }

        public IQueryable<OrderDetail> GetOrderDetails(int orderId)
        {
            return _dataContext.OrderDetails.Where(o => o.OrderID == orderId);
        }
        #endregion
    }
}